

// @ts-nocheck
import http from './http';
import {
    getSessionStorage, setSessionStorage
} from "@/utils/storage";

//权限
function userResource(model){
    return http.post("/api/v1/base/user/resource", model)
}

//一些公共配置
function baseConfigInfo(){
    const model = {
        configList: [
            "REMARK_FILE",
            "DEPARTMENT",
            "SICKNESS_TYPE",
            "PROJECT_FUNCTION",
            "ANNO_PROJECT_TARGET",
            "AUDIT_PROJECT_TARGET",
            "MODALITY",
            "MAIN_SERIES_MODE",
            "GROUP",
            "DISCARD_REASON",
            "WINDOW",
            "PROJECT_DATA_TYPE",
            "IMAGE_ANNO",
            "IMAGE_TOOL",
            "ALG_INFO",
            "SERIES_FIELD",
            "BODY_PART",
            "MODALITY",
        ]
    }
    return http.post("/aaa/v1/common/config/get", model);
}

//公共数据
function getCommonData(){
    return http.post("/aaa/v1/dict/child/query", { value: null }) 
}

function getChildren(key, array){
    const index = array.findIndex(item=> item.value === key);
    const children = index > -1 ? array[index].children : [];
    return children;
}

async function getCommonDataByKey(keys){
    const array = await getCommonData();
    const list = Array.isArray(keys) ? keys.map( key => getChildren(key, array)) : getChildren(keys, array);
    return list;
}

async function getBaseConfigInfo(keys){
    const info = await baseConfigInfo();
    setSessionStorage("baseConfigInfo", info)
    if( Array.isArray(keys) ){
        return keys.map(key=> info[key]);
    }
    return keys ? info[keys] || [] : info;
}




export {
    userResource,
    getCommonData,
    baseConfigInfo,
    getBaseConfigInfo,
    getCommonDataByKey
}

